package request

import (
	"github.com/gin-gonic/gin"
	"github.com/go-playground/validator/v10"
)

// LoginRequest 定义登录接口的入参结构体
type LoginRequest struct {
	Code string `json:"code" binding:"required" validate:"required"`
}

// BindAndValidateLoginParam 绑定并校验请求参数
func BindAndValidateLoginParam(c *gin.Context) (*LoginRequest, error) {
	var req LoginRequest
	if err := c.ShouldBindJSON(&req); err != nil {
		return nil, err
	}
	validate := validator.New()
	if err := validate.Struct(&req); err != nil {
		return nil, err
	}
	return &req, nil
}
